home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 8352 / 8352.xpi / chrome / greasefire.jar / content / test / test_updater.js < prev    next >
Text File  |  2009-01-06  |  2KB  |  77 lines

  1. /*
  2.  * Copyright (C) 2008 by Steve Krulewitz <skrulx@gmail.com>
  3.  * Licensed under GPLv2 or later, see file LICENSE in the xpi for details.
  4.  */
  5. const Cc = Components.classes;
  6. const Ci = Components.interfaces;
  7. const Cr = Components.results;
  8.  
  9. function runTest() {
  10.  
  11.   var tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
  12.   var mainThread = tm.mainThread;
  13.  
  14.   var gfs = Cc["@skrul.com/greasefire/service;1"]
  15.               .getService(Ci.gfIGreasefireService);
  16.  
  17.   var u = Cc["@skrul.com/greasefire/updater;1"]
  18.             .getService(Ci.gfIUpdaterService);
  19.  
  20.   log("index date" + (new Date(gfs.indexDate)));
  21.  
  22.   var done = false;
  23.   var doCancel = false;
  24.  
  25.   u.addListener({
  26.     onUpdateStarted: function() {
  27.       log("onUpdateStarted");
  28.       if (doCancel) {
  29.         log("cancelling");
  30.         u.cancelUpdate();
  31.       }
  32.     },
  33.     onUpdateFinished: function(aStatus, aMessage) {
  34.       log("onUpdateFinished " + aStatus.toString(16) + " " + aMessage);
  35.       done = true;
  36.     },
  37.     onDownloadProgress: function(aCurrentBytes, aTotalBytes) {
  38.       //log("onDownloadProgress " + aCurrentBytes + " " + aTotalBytes);
  39.     }
  40.   });
  41.  
  42.   u.startUpdate(true);
  43.   while (!done) {
  44.     mainThread.processNextEvent(true);
  45.   }
  46.  
  47.   log("index date" + (new Date(gfs.indexDate)));
  48.  
  49.   done = false;
  50.   u.startUpdate(false);
  51.   while (!done) {
  52.     mainThread.processNextEvent(true);
  53.   }
  54.  
  55.   log("index date" + (new Date(gfs.indexDate)));
  56.  
  57. /*
  58.   doCancel = true;
  59.  
  60.   done = false;
  61.   u.startUpdate(true);
  62.   while (!done) {
  63.     mainThread.processNextEvent(true);
  64.   }
  65.  
  66.   log("index date" + (new Date(gfs.indexDate)));
  67. */
  68.   return true;
  69. }
  70.  
  71. function newUri(spec) {
  72.   var ioService = Cc["@mozilla.org/network/io-service;1"].
  73.                   getService(Ci.nsIIOService);
  74.  
  75.   return ioService.newURI(spec, null, null);
  76. }
  77.